<?php

/**
 * Created by PhpStorm.
 * User: shwy
 * Date: 2017/9/8
 * Time: 10:36
 * 项目管理相关接口
 */
class project extends CI_Controller
{


    public function __construct()
    {
        parent::__construct();
        $this->load->model('project_model');

    }

    // 用户筛选接口
    public function search()
    {
        //搜索条件开始时间和结束时间
        $argc = [];
        if(isset($_GET['startTime'])  && $_GET['startTime']){
            $argc += [
                'createTime >'=> strtotime($_GET['startTime']),
            ];
        }

        if(isset($_GET['endTime'])  && $_GET['endTime']){
            $argc += [
                'createTime <'=> strtotime($_GET['endTime']),
            ];
        }

        //搜索用户名
        if(isset($_GET['search']) && $_GET['search']){
            $searchArg = [
                'field' => 'name',
                'arg'=> $_GET['search'],
                'side' => 'both'
            ];
        }else{
            $searchArg = '';
        }

        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if(!$page){
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        }else{
            $start_position = ($page - 1) * $page_num;
        }

        if(!$argc){
            $argc = 0;
        }

        if($searchArg){
            $data = $this->project_model->search('*',$argc,$searchArg,$page_num,$start_position);
        }else{
            $data = $this->project_model->page('project',$argc,$page_num,$start_position);
        }
		$total_num 			= $data['total_num'];
		unset($data['total_num']);
		foreach ($data as $k => $v) {
			foreach ($v as $k2 => $v2) {
				$data[$k][$k2]['createTime'] = date('Y-m-d', $v2['createTime']);
			}
		}
        $data['pageNum'] 	= $page_num;
        $data['this_page'] 	= $page;
		$data['total_num']  = $total_num;
        echo json_encode($data,JSON_UNESCAPED_UNICODE);

    }


}










































